﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for Order
/// </summary>
public class Order
{
    #region"Properties"
    public int MaHD { get; set; }
    public int MaKH { get; set; }
    public DateTime NgayLapHD { get; set; }
    public decimal TongTien { get; set; }
    #endregion"End Properties"

    #region"Methods"
    /// <summary>
    /// Thêm 1 hóa đơn
    /// </summary>
    /// <param name="o"></param>
    public static void InsertOrder(Order o)
    {
        try
        {
            String StoredProcedureName = "sp_InsertOrder";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@MaHD", o.MaHD.ToString());
            d.Add("@MaKH", o.MaKH.ToString());
            d.Add("@NgayLapHD", o.NgayLapHD.ToShortDateString());
            d.Add("@TongTien", o.TongTien.ToString());
            DataAccess.ExecuteNonQuery(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Cập nhập hóa đơn
    /// </summary>
    /// <param name="o"></param>
    public static void UpdateOrder(Order o) 
    {
        try
        {
            String StoredProcedureName = "sp_UpdateOrder";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@MaHD", o.MaHD.ToString());
            d.Add("@MaKH", o.MaKH.ToString());
            d.Add("@NgayLapHD", o.NgayLapHD.ToShortDateString());
            d.Add("@TongTien", o.TongTien.ToString());
            DataAccess.ExecuteNonQuery(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Xóa hóa đơn
    /// </summary>
    /// <param name="o"></param>
    public static void DeleteOrder(Order o) 
    {
        try
        {
            String StoredProcedureName = "sp_DeleteOrder";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@MaHD", o.MaHD.ToString());
            DataAccess.ExecuteNonQuery(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Lấy danh sách các hóa đơn theo MaKH
    /// </summary>
    /// <param name="CustomerID"></param>
    /// <returns>DataTable</returns>
    public static DataTable GetOrderByCustomerID(int CustomerID)
    {
        try
        {
            String StoredProcedureName = "sp_GetOrderByCustomerID";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@CustomerID", CustomerID.ToString());
            return DataAccess.GetList(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Lấy danh sách các Hóa đơn theo tongTienBatDau->tongTienKetThuc
    /// </summary>
    /// <param name="tongTienBatDau"></param>
    /// <param name="tongTienKetThuc"></param>
    /// <returns>DataTable</returns>
    public static DataTable GetOrderBySubTotal(decimal tongTienBatDau, decimal tongTienKetThuc) 
    {
        try
        {
            String StoredProcedureName = "sp_GetOrderBySubTotal";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@tongTienBatDau", tongTienBatDau.ToString());
            d.Add("@tongTienKetThuc", tongTienKetThuc.ToString());
            return DataAccess.GetList(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    /// <summary>
    /// Lấy danh sách hóa đơn theo ngày: startDate->endDate
    /// </summary>
    /// <param name="StartDate"></param>
    /// <param name="EndDate"></param>
    /// <returns></returns>
    public static DataTable GetOrderByTime(DateTime StartDate, DateTime EndDate) 
    {
        try
        {
            String StoredProcedureName = "sp_GetOrderByTime";
            IDictionary<String, String> d = new Dictionary<String, String>();
            d.Add("@StartDate", StartDate.ToShortDateString());
            d.Add("@EndDate", EndDate.ToShortDateString());
            return DataAccess.GetList(StoredProcedureName, d);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    #endregion"End Methods"
}
